home *** CD-ROM | disk | FTP | other *** search
- #
- # loop.test
- #
- # Tests for the loop command.
- #---------------------------------------------------------------------------
- # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
- #
- # Permission to use, copy, modify, and distribute this software and its
- # documentation for any purpose and without fee is hereby granted, provided
- # that the above copyright notice appear in all copies. Karl Lehenbauer and
- # Mark Diekhans make no representations about the suitability of this
- # software for any purpose. It is provided "as is" without express or
- # implied warranty.
- #------------------------------------------------------------------------------
- # $Id: loop.test,v 2.0 1992/10/16 04:50:01 markd Rel $
- #------------------------------------------------------------------------------
- #
-
- if {[info procs test] != "test"} then {source testlib.tcl}
-
- test loop-1.1 {loop tests} {
- set a {}
- set i 1
- loop i 1 6 {
- set a [concat $a $i]
- }
- set a
- } {1 2 3 4 5}
-
- test loop-1.2 {loop tests} {
- set a {}
- loop i 1 6 {
- if {$i == 4} {
- continue}
- set a [concat $a $i]
- }
- set a
- } {1 2 3 5}
-
- test loop-1.3 {loop tests} {
- set a {}
- loop i 1 6 {
- if $i==4 break
- set a [concat $a $i]
- }
- set a
- } {1 2 3}
-
- test loop-1.4 {loop tests} {
- list [catch {loop 1 2 3} msg] $msg
- } {1 {wrong # args: loop var first limit [incr] command}}
- test loop-1.5 {loop tests} {
- list [catch {loop 1 2 3 4 5 6} msg] $msg
- } {1 {wrong # args: loop var first limit [incr] command}}
-
- test loop-1.6 {loop tests} {
- set a {}
- loop i 1 6 {
- set a [concat $a $i]
- set i 100
- }
- set a
- } {1 2 3 4 5}
-
- test loop-1.7 {loop tests} {
- set a {}
- loop i 1 6 2 {
- set a [concat $a $i]
- }
- set a
- } {1 3 5}
-
- test loop-1.8 {loop tests} {
- set a {}
- set i 1
- loop i 6 1 -1 {
- set a [concat $a $i]
- }
- set a
- } {6 5 4 3 2}
-
- test loop-1.9 {loop tests} {
- set a {}
- loop i 6 1 -1 {
- if $i==4 {
- continue}
- set a [concat $a $i]
- }
- set a
- } {6 5 3 2}
-
- test loop-1.10 {loop tests} {
- set a {}
- loop i 6 1 -1 {
- if {$i == 4} {
- break}
- set a [concat $a $i]
- }
- set a
- } {6 5}
-
- test loop-1.11 {loop tests} {
- set j 0
- loop i 65536 65556 {
- incr j
- }
- set j
- } 20
-
- test loop-1.12 {loop tests} {
- set j 0
- loop i 65556 65536 -1 {
- incr j 1
- }
- set j
- } 20
-
- test loop-1.13 {loop tests} {
- set j 0
- loop i 0 655360 65536 {
- incr j 1
- }
- set j
- } 10
-
- test loop-1.13 {loop tests} {
- set j 0
- loop i 655360 0 -65536 {
- incr j 1
- }
- set j
- } 10
-
-